package org.grayrabbit.cms.action.system;

import java.io.File;
import java.util.ArrayList;
import java.util.List;

import org.dom4j.Document;
import org.dom4j.Element;
import org.dom4j.io.SAXReader;
import org.grayrabbit.cms.entity.OperCode;

/**
 * 读取权限xml文件，构建权限代码实体集合
 * 
 * 暂时留存，节点权限代码最终确定后 ，删除
 * 
 *  hasau 2011-05-11 17:00:00
 * 
 */
public class ReadOperCodeXML {
	static List<OperCode>  loadOperCodes() throws Exception{
		
		 SAXReader reader = new SAXReader();
		 	 
		 /**  xml文件在  src\main\resources\init\NewFile.xml
		  *    
		  *   这个xml文件是权限节点代码文件 cmsOperCode.xml的
		  *   结构简化版
		  *   具体逻辑结构请参阅 src\main\resources\init\ cmsOperCode.xml
		  * */
		 String filename = "F:/NewFile.xml";
         Document document = reader.read(new File(filename));
		 Element root = document.getRootElement();
		 @SuppressWarnings("unchecked")
		 List<Element>  list =root.elements();  
		 OperCode operCode=null;
		 List<OperCode>  operCodeList = new ArrayList<OperCode>();
		 for(Element e :list){			 
			 operCode = new OperCode();
			 operCode.setOperCode(e.attributeValue("code"));
			 operCode.setOperName(e.attributeValue("name"));
			 operCode.setOperType(e.attributeValue("type"));
			 
			 operCodeList.add(operCode);		 
		 }
		 
		return operCodeList;
	}
	
	public static void main(String[] args) throws Exception {
		loadOperCodes();
	}
}
